#include "wx_pch.h"
#include "DialogList.h"

#include "Database.h"
#include "Action.h"
#include "Log.h"
#include "GlobalParam.h"

#ifndef WX_PRECOMP
	//(*InternalHeadersPCH(DialogList)
	#include <wx/intl.h>
	#include <wx/string.h>
	#include <wx/listbox.h>
	//*)
#endif
//(*InternalHeaders(DialogList)
//*)

//(*IdInit(DialogList)
const long DialogList::ID_BOOKLIST = wxNewId();
const long DialogList::ID_BUTTON1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(DialogList,wxDialog)
	//(*EventTable(DialogList)
	//*)
END_EVENT_TABLE()

DialogList::DialogList(wxWindow* parent,wxWindowID id)
{
	//(*Initialize(DialogList)
	Create(parent, id, wxEmptyString, wxDefaultPosition, wxSize(500,800), wxDEFAULT_DIALOG_STYLE, _T("id"));

	BookList = new wxListCtrl(this,ID_BOOKLIST,wxPoint(100,200),wxSize(300,300),wxLC_REPORT|wxSUNKEN_BORDER|wxLC_EDIT_LABELS);
	Button1 = new wxButton(this, ID_BUTTON1, _("Label"), wxPoint(192,660),wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));

    BookList->InsertColumn(0, _T("First Column"));
    BookList->InsertColumn(1, _T("Second Column"));
    BookList->SetColumnWidth(0, 150);
    BookList->SetColumnWidth(1, 150);
    BookList->SetItemCount(1000000);

	Connect(ID_BOOKLIST,wxEVT_COMMAND_LISTBOX_SELECTED,(wxObjectEventFunction)&DialogList::OnBookListSelect);
	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&DialogList::OnButton1Click);
	//*)
}

DialogList::~DialogList()
{
	//(*Destroy(DialogList)
	//*)
}


void DialogList::OnBookListSelect(wxCommandEvent& event)
{
}

void DialogList::OnButton1Click(wxCommandEvent& event)
{
    /*
    wxString title = wxString::FromUTF8("title");
    wxString confirm = wxString::FromUTF8("confirm");

    for ( int i = 0; i < NUM_ITEMS; i++ )
    {
        BookList->InsertItem(i, wxString::Format(_T("Item %d 0"), i), 1);
        BookList->SetItem(i, 1, wxString::Format(_T("Item %d 1"), i));
    }

    wxMessageBox(title,confirm,wxYES_NO|wxCANCEL,this);
    */

    DBSqlite* ThisDatabase = new DBSqlite("database","db.sql");
    Action* ThisAction = new Action(ThisDatabase);

    ThisAction->ImportBooksFromDirectory("/home/frank/bptest/");
    ThisAction->ReadPage(1);

    for ( int i = 0; i < BOOK_INFO_LIST_LENGTH; i++ )
    {
        BookList->InsertItem(i, wxString(g_pool.InfoList->List[i].BookFilePath.c_str(),wxConvUTF8), 1);
        BookList->SetItem(i, 1, wxString(g_pool.InfoList->List[i].BookName.c_str(),wxConvUTF8));
    }


    delete ThisDatabase;
    delete ThisAction;
}
